﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Compiled_Tests;
using Tedds_Tool.RulesBase;
using LEET.StandardModuals.Instructions;
using LEET.LEETCommon.Model;
using LEET.CommonInterfaces.Compilers;
using LEET.LEETCommon;
using LEET.Utilities;
using LEET.CommonInterfaces.TestControls;

namespace Tedds_Tool.Instructions
{
    public class RuleBase : Instruction, IRuleBaseInstruction
    {
        public RuleBase(String[] args)
            : base(args)
        {
            IEnumerator<String> iter = Rules.GetEnumerator();
            if(iter.MoveNext())
            {
                Name = iter.Current;
                while(iter.MoveNext())
                    Name += " | " + iter.Current;
            }
            InstructionType = NodeTypes.RULE_TYPE;
        }

        public static IAutomationActionResult StaticCall()
        {
            //TODO
            return null;
        }

        public override String RenderStaticCall()
        {
            //TODO
            return "Tedds_Tool.Instructions.RuleBase.StaticCall()";
        }


        [Obsolete("This should now be replaced by RenderStaticCall", false)]
        protected override string MethodBody(AssertionSet asserts)
        {
            StringBuilder buf = new StringBuilder();
            buf.Append("                RB.IRuleBase rb = new RB.RuleBase();\r\n");
            foreach (String rule in Rules)
                buf.Append("                rb.AddRule(new " + rule + "());\r\n");
            buf.Append("                return new AutomationActionResult(rb);\r\n");
            return buf.ToString();
        }

        [Obsolete("This should now be replaced by RenderStaticCall", false)]
        protected override string RenderedMethodName(int i)
        {
            return "RuleBase";
        }

        public override string PlainText()
        {
            return "Define Rules to be adhered to.";
        }

        public IEnumerable<string> Rules { 
            get 
            {
                for (int i = 1; i < args.Length; i++)
                    yield return Helpers.NormalizeClassName(args[i].Trim());
            } 
        }
    }
}
